package com.mjlf.algorithms.sort;

/**
 * @auther a123
 * @create 2018-09-05 19:32
 * @desc 排序工具类
 */
public class SortUtil {

    /**
     * 判断元素a 是否小于元素b
     * @param a
     * @param b
     * @return
     */
    public static boolean less(Comparable a, Comparable b){
        if(a.compareTo(b) < 0){
            return true;
        }
        return false;
    }

    public static boolean lessOrEqual(Comparable a, Comparable b){
        if(a.compareTo(b) <= 0){
            return true;
        }
        return false;
    }

    /**
     * 元素交换
     * @param elements
     * @param a
     * @param b
     */
    public static void exch(Comparable[] elements, int a, int b){
        Comparable cache = elements[a];
        elements[a] = elements[b];
        elements[b] = cache;
    }

    public static void show(Comparable[] elements){
        for(Comparable el : elements){
            System.out.print(el + " ");
        }
        System.out.println();
    }
}
